package org.example.myleet.p884;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Solution {
    public String[] uncommonFromSentences(String s1, String s2) {
        String[] words = s1.split(" ");
        HashMap<String, Integer> wordCount = new HashMap<>(words.length);
        for (String word : words) {
            int count = wordCount.computeIfAbsent(word, key -> 0);
            ++count;
            wordCount.put(word, count);
        }
        words = s2.split(" ");
        for (String word : words) {
            int count = wordCount.computeIfAbsent(word, key -> 0);
            ++count;
            wordCount.put(word, count);
        }
        List<String> result = new ArrayList<>(words.length);
        for (Map.Entry<String, Integer> entry : wordCount.entrySet()) {
            if (entry.getValue() == 1) {
                result.add(entry.getKey());
            }
        }
        return result.toArray(new String[0]);
    }
}
